#####################################################################
# File:         Selection.py
# Product:      KnowledgeEngine
#
# Copyright:    Copyright (c) 2001, Faulkner Ltd.
# Author:       Brian Oliver
#
# Description:  This file defines the Selection class, the 
#               Option component container.
#
# See Also:     ComponentContainer, Model
#####################################################################

#####################################################################
## Knowledge Engine Library Imports
from Products.KnowledgeEngine.Common import *
from Products.KnowledgeEngine.KnowledgeEngineCore import *
from Products.KnowledgeEngine.ComponentContainer import ComponentContainer, ComponentContainerInfo
from Products.KnowledgeEngine.Components.Section.Section import Section
from Products.KnowledgeEngine.Library.Library import Library
from Products.KnowledgeEngine.PropertyDefinition import *
from Products.KnowledgeEngine.PropertyTypes import *
from Products.KnowledgeEngine.PropertyFormats import *
from Products.KnowledgeEngine.PropertyStructures import *

#####################################################################
## Zope Library Imports
from Globals import DTMLFile
from ImageFile import ImageFile

#####################################################################
## Python Library Imports
# (none)

#####################################################################
## SelectionInfo Class Definition
class SelectionInfo(ComponentContainerInfo):
    """
        Defines the class info methods, defining information about
        the class without needing an instance of the class
    """

    #---------------------------------------------------------------#

    def getClassName(self):
        """
            Return the class name
        """
        return 'Selection'

    #---------------------------------------------------------------#

    def getDisplayName(self):
        """
            Return a friendly name for the class instances
            (this is used for displaying in lists etc)
        """
    
        return "Selection"
        
    #---------------------------------------------------------------#

    def getIdentityType(self):
        """
            Return the identity type.  
        """
        
        return "sel"
        
    #---------------------------------------------------------------#
    
    def getClassIcon(self):
        """
            Return the appropriate icon file for the class.
        """
        
        return ImageFile('www/icon.gif', globals())

    #---------------------------------------------------------------#

    def isChildPermitted(self, childClassInfo, childInstance = None):
        """
            Returns if the specified child is permitted as a 
            child of the class' instances.
            
            NOTE: This is from this class' instance perspective.
            
            For component containers, this always overrides what the
            return value from childClassInfo.isPermittedInContainer(...)
        """
        
        #DEFAULT RULE: Selections may have Option children
        return childClassInfo.isInstanceOf('Option')
    
    #---------------------------------------------------------------#

    def onConfigureProperties(self):
        """
            Automatically called by the Knowledge Engine once
            the class has been loaded.  Use this method to register 
            class specific properties using the PropertyReflection interface.
            
            If this class is sub-classed, a call must be made to
            the super-class to ensure super-class properties are
            correctly registered
            
            NOTE: This method is called before ClassInfo.onAfterStartup()            
        """

        #initialise the super-class properties for reflection
        ComponentContainerInfo.onConfigureProperties(self)

        #add the 'displayFormat' property        
        self.addPropertyDefinition(PropertyDefinition(identity="displayFormat", displayName="Display As", description="How options are to be selected/displayed?", propertyType=pt_STRING, propertyFormat=pf_NATIVE, hasEnumeratedValues=true, enumeratedValuesList=['Radio Buttons','Dropdown List','Check Boxes'], defaultValue="Radio Buttons"))

    #---------------------------------------------------------------#

#####################################################################
## Selection Class Definition
class Selection(ComponentContainer):
    """
        The Option Component Container
    """

    #---------------------------------------------------------------#

    #TRANSIENT: a ClassInfo implementation instance to provide info about this class
    _CLASSINFO = SelectionInfo()
   
    #---------------------------------------------------------------#

    DISPLAY_FORMAT_OPTIONS = ['Radio Buttons','Dropdown List','Check Boxes']
 
    #---------------------------------------------------------------#

    # DTML Methods
    index_html = DTMLFile('dtml/index_html', globals())
    simplereport_html = DTMLFile('dtml/simplereport_html', globals())
    scoredreport_html = DTMLFile('dtml/scoredreport_html', globals())
    scored360report_html = DTMLFile('dtml/scored360report_html', globals())
    groupedreport_html = DTMLFile('dtml/groupedreport_html', globals())    

    #---------------------------------------------------------------#

    def __init__(self, id, identity):
        "Constructor for the Selection"        

        ComponentContainer.__init__(self, id, identity)

    #---------------------------------------------------------------#

    def getDisplayFormat(self):
        "Return the display format of the selection"
        
        return self.displayFormat

    #---------------------------------------------------------------#

    def setDisplayFormat(self, displayFormat):
        "Set the display format of the selection"
        
        self.displayFormat = displayFormat

    #---------------------------------------------------------------#

#####################################################################
## Class Initialisation

# Register Component Information with the Knowledge Engine
registerGenericObjectClass(Selection)

#####################################################################
